package fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.example.a513.R;

import java.util.List;

import adpater.BillListAdapter;
import database.BillDBHelper;
import entity.BillInfo;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link BillFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class BillFragment extends Fragment {


    public static BillFragment newInstance(String yearMonth) {
        BillFragment fragment = new BillFragment();
        Bundle args = new Bundle();
        args.putString("yearMonth",yearMonth);
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        Bundle bundle = getArguments();
        String yearMonth = bundle.getString("yearMonth");
        View view = inflater.inflate(R.layout.fragment_bill, container, false);
         ListView listView = view.findViewById(R.id.lv_bill);
        BillDBHelper mHelper = BillDBHelper.getInstance(getContext());
        mHelper.openReadLink();
        
        List<BillInfo> infos = mHelper.queryAllBillInfo(yearMonth);
        BillListAdapter adapter = new BillListAdapter(infos,getContext());
        listView.setAdapter(adapter);
        return view;
    }
}